{% extends "main_view.html" %}
{% block center %}
<p>The number encoded in the returned picture equals the first 6 HEX numbers of md5(token+secret). P.S. HEX numbers are mod by 10 to map to 0 to 9.</p>
<p><i>
 For example:<br> 
 md5(<b>hello</b>agt2aXN1YWxjaGVja3IRCxILTnVtYmVySW1hZ2UYFgw)=<b>7C82C0</b>3A77EAA8440FBAC76852BA25B3<br>
 If you send http://visualcheck.appspot.com/display?id={{id}}&token=<b>hello</b>, the returned picture contains number "<b>728220</b>"
</i></p>
<div>Python sample for your reference</div>
<samp>
&nbsp;# Validate if the user input numbers equals the numbers<br>
&nbsp;# encoded in the picture<br>
&nbsp;# numbers: the user input<br>
&nbsp;# token: the token sent when requesting the picture<br>
&nbsp;def isTokenValid(self, numbers, token):<br>
&nbsp;&nbsp;&nbsp;try:            <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encrypt = md5.new()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encrypt.update(token)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;encrypt.update("{{secret}}")   # Your secret given after signup<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;md5token = encrypt.hexdigest().upper()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logging.debug("Excepted:"+md5token+" Actual:"+numbers)<br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# HEX values A to F are mapped to numbers 0 to 5          <br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for i in [0,1,2,3,4,5]:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if md5token[i] == numbers[i]:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'A' and numbers[i] == '0':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'B' and numbers[i] == '1':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'C' and numbers[i] == '2':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'D' and numbers[i] == '3':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'E' and numbers[i] == '4':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif md5token[i] == 'F' and numbers[i] == '5':<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return False<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return True<br>
&nbsp;&nbsp;&nbsp;except:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return False<br>
</samp>
{% endblock center %}